package quangtqServlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import quangtq.MailPagingRemote;

@WebServlet(name="DeleteMailServlet", urlPatterns={"/DeleteMailServlet"})
public class DeleteMailServlet extends HttpServlet {
    @EJB
    private MailPagingRemote mailPaging;
   
    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    {
        String strMailIDs = req.getParameter("mailIDs");
        StringTokenizer st = new StringTokenizer(strMailIDs, ",");
        String[] arrMailIDs = new String[st.countTokens()];

        int i = 0;
        while(st.hasMoreTokens())
        {
            arrMailIDs[i] = st.nextToken();
            i++;
        }

        int numOfDeletedMail = mailPaging.deleteMails(arrMailIDs);

        res.setContentType("text/xml");
        res.setHeader("Cache-Control", "no-cache");
        res.getWriter( ).write(String.valueOf(numOfDeletedMail));
    }
}
